﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}@using LeSoft.Application.Code;
<script>
    var _organizeid = "@OperatorProvider.Provider.Current().CompanyId", _pstructId = "";
    $(function () {
        InitialPage();
        GetTree();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 141.5);
                $("#itemTree").setTreeHeight($(window).height() - 55.5);
            }, 200);
            e.stopPropagation();
        });
        //组织机构
        $("#PStructTree").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            description: "==请选择组织机构==",
            height: "250px",
            click: function (item) {
                _organizeid = item.id;
                GetTree();
            }
        });

        $("#PStructTree").ComboBoxTreeSetValue(_organizeid);
    }
    function GetTree() {
        var item = {
            height: $(window).height() - 55.5,
            url: "../../ResourceManage/RS_PStructs/GetTreeNameJson?OrganizeId=" + _organizeid,
            onnodeclick: function (item) {
                _pstructId = item.id;
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        var queryJson = $("#filter-form").GetWebControls();
        queryJson["PStructId"] = _pstructId;
        queryJson["OrganizeId"] = _organizeid;
        $gridTable.jqGrid({
            url: "../../SystemManage/Member/GetListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", index: "Id", hidden: true },
                { label: "会员编号", name: "Code", index: "Code", width: 150, align: "left" },
                 { label: "会员昵称", name: "NickName", index: "NickName", width: 150, align: "left" },
                { label: "会员名称", name: "Name", index: "Name", width: 150, align: "left" },
                {
                    label: "会员状态", name: "State", index: "State", width: 70, align: "center",
                    formatter: function (cellvalue) {
                        return cellvalue == 0 ? "<span class=\"label label-danger\">无效</span>" : "<span class=\"label label-success\">有效</span>";
                    }
                },
                { label: "手机号码", name: "Phone", index: "Phone", width: 100, align: "left" },
                { label: "身份证号", name: "IDCard", index: "IDCard", width: 100, align: "left" },
                { label: "备注", name: "Description", index: "Description", width: 200, align: "left" }
            ],
            viewrecords:true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'MemberID',
            sortorder: 'asc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value);
            $("#btn_Search").trigger("click");
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = $("#filter-form").GetWebControls();
            queryJson["PStructId"] = _pstructId;
            queryJson["OrganizeId"] = _organizeid;
            queryJson["Code"] = $("#queryCondition").find('.dropdown-text').attr('data-value') == "Code" ? $("#txt_Keyword").val() : "",
           queryJson["Name"] = $("#queryCondition").find('.dropdown-text').attr('data-value') == "Name" ? $("#txt_Keyword").val() : "",
           queryJson["NickName"] = $("#queryCondition").find('.dropdown-text').attr('data-value') == "NickName" ? $("#txt_Keyword").val() : "",
           queryJson["Phone"] = $("#queryCondition").find('.dropdown-text').attr('data-value') == "Phone" ? $("#txt_Keyword").val() : "",
            $gridTable.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) }
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑会员资料',
                url: '/SystemManage/Member/Form?keyValue=' + keyValue,
                width: "1100px",
                height: "800px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }

    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: '/SystemManage/Member/RemoveForm',
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的会员！', 0);
        }
    }
    //禁用
    function btn_disabled(keyValue) {
        if (keyValue == undefined) {
            keyValue = $("#gridTable").jqGridRowValue("Id");
        }
        if (checkedRow(keyValue)) {
            $.ConfirmAjax({
                msg: "注：您确定要【禁用】会员？",
                url: "../../BaseManage/Account/DisabledAccount",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        }
    }
    //启用
    function btn_enabled(keyValue) {
        if (keyValue == undefined) {
            keyValue = $("#gridTable").jqGridRowValue("Id");
        }
        if (checkedRow(keyValue)) {
            $.ConfirmAjax({
                msg: "注：您确定要【启用】会员？",
                url: "../../BaseManage/Account/EnabledAccount",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        }
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title" style="padding:0px;"><div id="PStructTree" type="selectTree" class="ui-select"></div></div>
            <div id="itemTree" style=" height: 320px; border-bottom: 1px dashed #cecece;"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>
                                <div id="queryCondition" class="btn-group">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="Code">编码</a></li>
                                        <li><a data-value="Name">名称</a></li>
                                        <li><a data-value="NickName">昵称</a></li>
                                        <li><a data-value="Phone">手机号码</a></li>
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <label id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</label>
                        @*<label id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</label>*@
                        <label id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</label>
                        @*<label id="lr-details" class="btn btn-default" onclick="btn_details()"><i class="fa fa-pencil-square-o"></i>&nbsp;详情</label>*@
                        <label id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</label>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>
